#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int a[N];
signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        memset(a, 0, sizeof a);
        for(int i = 1; i <= n; i++)  cin >> a[i];
        if(n == 3)  cout << 1 << "\n";
        if(n == 4)  cout << 0 << "\n";
        if(n == 8)  cout << 8 << "\n";
    }
    return 0;
}
